package homework2;

import tester.Tester;

public class Examples {
	Examples() {
	}

	Soccer soccerTeamA = new Soccer("Brazil", 1, 9, "GOD");
	Soccer soccerTeamB = new Soccer("Netherlands", 3, 9, "Demigod");
	Soccer soccerTeamC = new Soccer("England", 4, 9, "Zeus");
	Soccer soccerTeamD = new Soccer("India", 5, 9, "Bob");
	Soccer soccerTeamE = new Soccer("Mars", 2, 9, "Zenu");
	Soccer soccerTeamF = new Soccer("Androme Galaxy", 6, 9, "Cthulhu");
	
	/*
	 * Magical first battle between Mars and India. Somehow, India Wins.
	 */
	SoccerScore initialScore = new SoccerScore(1, 2, false);
	MatchData initialData = new MatchData(soccerTeamE, soccerTeamD, initialScore);
	InitMatch initialWinner = new InitMatch(initialData);
	
	/*
	 * Battle between Cthulhu and Netherlands. And Netherlands awesomely wins.
	 */
	SoccerScore initial2Score = new SoccerScore(2, 1, false);
	MatchData initial2Data = new MatchData(soccerTeamB, soccerTeamF, initial2Score);
	InitMatch initial2Winner = new InitMatch(initial2Data);

	/*
	 * First match A match between Netherlands and India, Netherlands wins
	 */
	SoccerScore firstScore = new SoccerScore(9000, 1, false);
	MatchData firstData = new MatchData(soccerTeamB, soccerTeamD, firstScore);
	AdvanceMatch firstWinner = new AdvanceMatch(firstData, initialWinner, initial2Winner);
	
	/*
	 * Alternative to the last match without being on harry potter world
	 */
	SoccerScore altFirstScore = new SoccerScore(9000, 1, false);
	MatchData altFirstData = new MatchData(soccerTeamB, soccerTeamD, altFirstScore);
	InitMatch altFirstWinner = new InitMatch(altFirstData);

	/*
	 * Semi-final match 1 A match between Brazil and England, Brazil wins
	 */
	SoccerScore semiOneScore = new SoccerScore(2, 1, false);
	MatchData semiOneData = new MatchData(soccerTeamA, soccerTeamC,
			semiOneScore);
	InitMatch semiOneWinner = new InitMatch(semiOneData);

	/*
	 * Final match, Brazil vs Netherlands, Brazil wins
	 */
	SoccerScore finalScore = new SoccerScore(1, 0, false);
	MatchData finalMatchData = new MatchData(soccerTeamA, soccerTeamB,
			finalScore);
	AdvanceMatch finalWinner = new AdvanceMatch(finalMatchData, semiOneWinner,
			firstWinner);
	
	/*
	 * Alternative to the last match without being on harry potter world
	 */
	SoccerScore altFinalScore = new SoccerScore(1, 0, false);
	MatchData altFinalMatchData = new MatchData(soccerTeamA, soccerTeamB,
			altFinalScore);
	AdvanceMatch altFinalWinner = new AdvanceMatch(altFinalMatchData, semiOneWinner,
			altFirstWinner);

	public void testTournament(Tester T) {
		T.checkExpect(finalWinner.allValid(), true);

		T.checkExpect(finalWinner.matchesPlayed(soccerTeamA), 2);
		T.checkExpect(finalWinner.matchesPlayed(soccerTeamD), 2);
		T.checkExpect(firstWinner.matchesPlayed(soccerTeamA), 0);

		T.checkExpect(finalWinner.hasInvariant(), false);

		T.checkExpect(finalWinner.winnerAlwaysAdvanced(), true);

		T.checkExpect(finalWinner.winnerMovesOn(), soccerTeamA);

		T.checkExpect(finalWinner.depth(), 5);
		T.checkExpect(semiOneWinner.depth(), 1);
		T.checkExpect(firstWinner.depth(), 3);
	}
	
	public void testInvarientTournament(Tester T) {
		T.checkExpect(altFinalWinner.hasInvariant(), true);
	}

	public void testRanked(Tester T) {
		T.checkExpect(soccerTeamA.hasBetterRanking(soccerTeamB), true);
		T.checkExpect(soccerTeamA.hasBetterRanking(soccerTeamC), true);
		T.checkExpect(soccerTeamA.hasBetterRanking(soccerTeamD), true);

		T.checkExpect(soccerTeamC.hasBetterRanking(soccerTeamA), false);
	}

	public void testScore(Tester T) {
		T.checkExpect(firstScore.isValid(), true);
		T.checkExpect(semiOneScore.isValid(), true);
		T.checkExpect(finalScore.isValid(), true);
	}

	public void testTeam(Tester T) {
		T.checkExpect(soccerTeamA.getCaptain(), "GOD");
		T.checkExpect(soccerTeamC.getPlayerCount(), 9);
	}

	public static void main(String[] args) {
		Tester.run(new Examples());
	}

}
